home *** CD-ROM | disk | FTP | other *** search
- Path: news.nacm.com!usenet
- From: brandon@criterion.com (Brandon Wallace)
- Newsgroups: comp.lang.c
- Subject: Re: mmap question
- Date: 15 Jan 1996 20:43:51 GMT
- Organization: Nicholas|Applegate Capital Management, San Diego, CA
- Message-ID: <4deea7$7cp@news.nacm.com>
- References: <4cgm6a$1n2@holodeck.iss.nus.sg>
- NNTP-Posting-Host: 204.255.80.4
- X-Newsreader: knews 0.9.2
-
- In article <4cgm6a$1n2@holodeck.iss.nus.sg>,
- paulwu@iss.nus.sg (Paul Wu) writes:
- -> Hi, there,
- ->
- -> It's myself again. I think I have solved my previous problem by changing
- -> the file POINTER to be file DESCRIPTOR (using open rather than fopen) and
- -> a bit careful about the constraints posed on the off argument.
- ->
- -> Now the problem is I encounter a bus error SIGBUS (10) when I am actually
- -> accessing the mapped memory, as an array. Anything about the other
- -> parameters that I should pay attention to, again my codes look like:
- ->
- -> ctr_tbl->trieArray=(UC_TRIE_NODE *)(mmap((caddr_t)0, off_set2,
- -> PROT_READ, MAP_SHARED, *fdesc, (off_t)(off_set1-j))+j);
- ->
- -> Should I be more careful about the PROT_READ and MAP_SHARED parameters?
- ->
- -> One last question, for those who have used mmap, does it really help?
- -> If so, in what particular aspects it helps? Is it the run time? or is it
- -> the saving of space? BUt it seems not likely for the latter, since it
- -> eats up the virtual memory anyway..
- ->
- -> Appreciated,
- -> Paul
-
- Why don't you just do:
-
- ctr_tbl->trieArray = (UC_TRIE_NODE *) mmap (0, off_set2/* I hope this is a length parameter
- that is an integral multiple of sizeof (UC_TRIE_NODE) */
- , PROT_READ, MAP_SHARED, *fdesc, off_set1);
-
- instead of subtracting and adding j. Also, since you pass PROT_READ, you cannot modify
- this data, so you should probably cast it to a (UC_TRIE_NODE const *) instead. Make sure
- off_set1 satisfies the alignment constraints that the man pages mention. If it does not,
- then the way to fix it is to modify the file to meet these constraints, not to subtract
- j and then add it again after the call. Also note: don't store pointers in this mapped file
- because everytime you run the program, mmap() might return a different address and the
- pointers will be invalid.
- --
- Brandon Wallace
- Nicholas | Applegate Capital Management
- mailto:bman@criterion.com http://www.criterion.com/home-pages/brandon
- "I live life face down in the fast lane."
-
-